/*
Rotate Image 

You are given an n x n 2D matrix representing an image.

Rotate the image by 90 degrees (clockwise).

Follow up:
Could you do this in-place?

*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
#include <fstream>
#include <sstream>
//#include <unordered_set>
//#include <unordered_map>
//#include "print.h"
using namespace std;

/**
* Definition for binary tree*/


class Solution {
public:
    void rotate(vector<vector<int> > &matrix) {
		int n = matrix.size();
		
		vector<vector<int> > temp(n, vector<int>(n));

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				temp[i][j] = matrix[i][j];
			}

		}
		

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				matrix[j][n-1-i] = temp[i][j];
			}

		}
		//for ( i = 0; i < length; i++)
		

		
    }
};




int main(int argc, char*argv[])
{
	//func();

	cout <<"Test For freopen"<< endl;

	int a1;
	freopen("testData.txt","r",stdin);
	while (cin >> a1)
		cout << a1<< endl;
	

	





	int a[] = { 1, 2, 3 };
	int b[] = { 4, 5, 6 };
	int c[] = { 7, 8, 9 };

	vector<int> vecInt1(a,a+3);
	vector<int> vecInt2(b, b + 3);
	vector<int> vecInt3(c, c + 3);

	vector<vector<int> > nums;
	nums.push_back(vecInt1);
	nums.push_back(vecInt2);
	nums.push_back(vecInt3);

	
	Solution s;
	
	for (int i = 0; i < nums.size(); i++)
	{
		for (int j = 0; j < nums.size(); j++)
		{
			cout << nums[i][j]<< " ";
		}
		cout << endl;
	}
	
	s.rotate(nums);
	
	cout<<"After rotate! "<<endl;
	for (int i = 0; i < nums.size(); i++)
	{
		for (int j = 0; j < nums.size(); j++)
		{
			cout << nums[i][j]<< " ";
		}
		cout << endl;
	}
	







	system("pause");
	return 0;
}